package com.learning.security.core.handler;

import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServices;
import org.springframework.security.web.authentication.rememberme.PersistentTokenRepository;

import javax.servlet.http.HttpServletRequest;
import java.util.Objects;

public class MyPersistentTokenBaseRememberMeService extends PersistentTokenBasedRememberMeServices {
    public MyPersistentTokenBaseRememberMeService(String key, UserDetailsService userDetailsService, PersistentTokenRepository tokenRepository) {
        super(key, userDetailsService, tokenRepository);
    }

    @Override
    protected boolean rememberMeRequested(HttpServletRequest request, String parameter) {
        String paramValue = request.getAttribute(parameter).toString();
        if (Objects.nonNull(parameter)) {
            if (paramValue.equalsIgnoreCase("true")
                    || paramValue.equalsIgnoreCase("on")
                    || paramValue.equalsIgnoreCase("yes")
                    || paramValue.equalsIgnoreCase("1")) {
                return true;

            }
        }
        return false;
    }
}
